
<template>
  <div class="birth-form-mystical">
    <div class="scroll-header">
      <h2>紫微斗数命盘推算系统</h2>
      <div class="celestial-decoration">
        <span class="decoration-symbol">☯</span>
        <span class="decoration-line">✦✦✦✦✦</span>
        <span class="decoration-symbol">☯</span>
      </div>
    </div>
    
    <div class="scroll-content">
      <div class="form-grid">
        <div class="form-item">
          <label>姓名</label>
          <div class="mystical-input">
            <input 
              v-model="form.name" 
              type="text" 
              placeholder="请输入您的姓名"
            >
            <span class="input-decoration">卦</span>
          </div>
        </div>
        
        <div class="form-item">
          <label>性别</label>
          <div class="mystical-select">
            <select 
              v-model="form.gender"
            >
              <option value="male">男</option>
              <option value="female">女</option>
            </select>
            <span class="select-decoration">☯</span>
          </div>
        </div>
        
        <div class="form-item">
          <label>出生年份</label>
          <div class="mystical-select">
            <select 
              v-model="form.birthYear"
              @change="updateDayOptions"
            >
              <option v-for="year in years" :key="year" :value="year">{{ year }}年</option>
            </select>
            <span class="select-decoration">年</span>
          </div>
        </div>
        
        <div class="form-item">
          <label>出生月份</label>
          <div class="mystical-select">
            <select 
              v-model="form.birthMonth"
              @change="updateDayOptions"
            >
              <option v-for="month in 12" :key="month" :value="month">{{ month }}月</option>
            </select>
            <span class="select-decoration">月</span>
          </div>
        </div>
        
        <div class="form-item">
          <label>出生日</label>
          <div class="mystical-select">
            <select 
              v-model="form.birthDay"
            >
              <option v-for="day in days" :key="day" :value="day">{{ day }}日</option>
            </select>
            <span class="select-decoration">日</span>
          </div>
        </div>
        
        <div class="form-item">
          <label>出生时辰</label>
          <div class="mystical-select">
            <select 
              v-model="form.birthHour"
            >
              <option value="1">子时 (23:00-00:59)</option>
              <option value="2">丑时 (01:00-02:59)</option>
              <option value="3">寅时 (03:00-04:59)</option>
              <option value="4">卯时 (05:00-06:59)</option>
              <option value="5">辰时 (07:00-08:59)</option>
              <option value="6">巳时 (09:00-10:59)</option>
              <option value="7">午时 (11:00-12:59)</option>
              <option value="8">未时 (13:00-14:59)</option>
              <option value="9">申时 (15:00-16:59)</option>
              <option value="10">酉时 (17:00-18:59)</option>
              <option value="11">戌时 (19:00-20:59)</option>
              <option value="12">亥时 (21:00-22:59)</option>
            </select>
            <span class="select-decoration">时</span>
          </div>
        </div>
        
        <div class="form-item">
          <label>日历类型</label>
          <div class="mystical-select">
            <select 
              v-model="form.birthSystem"
              @change="updateDayOptions"
            >
              <option value="lunar">农历</option>
              <option value="solar">阳历(公历)</option>
            </select>
            <span class="select-decoration">历</span>
          </div>
        </div>
        
        <div class="form-item">
          <label>出生地</label>
          <div class="mystical-input">
            <input 
              v-model="form.birthPlace" 
              type="text" 
              placeholder="如：北京市"
            >
            <span class="input-decoration">地</span>
          </div>
        </div>
        
        <div class="form-item">
          <label>
            流年设置
            <span class="hint">(预测年份)</span>
          </label>
          <div class="mystical-select">
            <select 
              v-model="form.currentYear"
            >
              <option v-for="year in currentYears" :key="year" :value="year">{{ year }}年</option>
            </select>
            <span class="select-decoration">运</span>
          </div>
        </div>
      </div>
      
      <div class="divination-button">
        <button @click="onCalculate">
          <span class="button-text">推算命盘</span>
          <span class="button-decoration">✧</span>
        </button>
      </div>
    </div>
    
    <div class="scroll-footer">
      <div class="celestial-decoration">
        <span class="decoration-line">✦✦✦✦✦</span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'BirthForm',
  data() {
    const currentYear = new Date().getFullYear();
    
    return {
      form: {
        name: '',
        gender: 'male',
        birthYear: 1990,
        birthMonth: 1,
        birthDay: 1,
        birthHour: 1,
        birthSystem: 'lunar',
        birthPlace: '',
        currentYear: currentYear
      },
      years: Array.from({length: currentYear - 1899}, (_, i) => i + 1900),
      days: Array.from({length: 31}, (_, i) => i + 1),
      currentYears: Array.from({length: 21}, (_, i) => currentYear - 10 + i)
    };
  },
  methods: {
    updateDayOptions() {
      const year = parseInt(this.form.birthYear);
      const month = parseInt(this.form.birthMonth);
      let daysInMonth;
      
      if (this.form.birthSystem === 'solar') {
        // 公历天数计算
        daysInMonth = new Date(year, month, 0).getDate();
      } else {
        // 农历天数计算（简化版）
        daysInMonth = this.getLunarDays(year, month);
      }
      
      this.days = Array.from({length: daysInMonth}, (_, i) => i + 1);
      
      // 确保选择的日期有效
      if (this.form.birthDay > daysInMonth) {
        this.form.birthDay = daysInMonth;
      }
    },
    
    getLunarDays(year, month) {
      // 简化的农历月份天数（实际应用中应使用专门的农历库）
      const commonMonthDays = {
        1: 29, 2: 30, 3: 29, 4: 30, 5: 29, 6: 30,
        7: 29, 8: 30, 9: 29, 10: 30, 11: 29, 12: 30
      };
      
      return commonMonthDays[month] || 30;
    },
    
    onCalculate() {
      if (!this.form.name) {
        alert('请输入姓名');
        return;
      }
      
      this.$emit('calculate', {...this.form});
    }
  },
  mounted() {
    this.updateDayOptions();
  }
};
</script>

<style scoped>
.birth-form-mystical {
  background-image: url('');
  background-color: #f9f3e9;
  border: 2px solid #d8c5a0;
  border-radius: 8px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1), 0 0 30px rgba(210, 175, 125, 0.2);
  padding: 2rem;
  position: relative;
  max-width: 800px;
  margin: 0 auto;
  font-family: 'SimSun', 'STFangsong', serif;
  color: #6b4b35;
}

.birth-form-mystical::before, .birth-form-mystical::after {
  content: '';
  position: absolute;
  width: 30px;
  height: 100%;
  top: 0;
  background-image: url('');
}

.birth-form-mystical::before {
  left: 0;
  border-right: 1px solid #d8c5a0;
}

.birth-form-mystical::after {
  right: 0;
  border-left: 1px solid #d8c5a0;
}

.scroll-header {
  text-align: center;
  margin-bottom: 2rem;
  position: relative;
}

.scroll-header h2 {
  font-size: 1.8rem;
  font-weight: bold;
  color: #8b5a2b;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
  margin: 0 0 0.5rem 0;
  letter-spacing: 4px;
}

.celestial-decoration {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 1rem 0;
}

.decoration-symbol {
  font-size: 1.2rem;
  color: #8b5a2b;
}

.decoration-line {
  margin: 0 1rem;
  color: #bc955c;
  letter-spacing: 4px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 1.5rem;
}

.form-item {
  position: relative;
}

.form-item label {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 1rem;
  color: #8b5a2b;
  font-weight: bold;
}

.hint {
  font-size: 0.8rem;
  color: #ab7d53;
  font-weight: normal;
}

.mystical-input, .mystical-select {
  position: relative;
  display: flex;
  align-items: center;
}

.mystical-input input, .mystical-select select {
  width: 100%;
  padding: 0.7rem 1rem;
  border: 1px solid #d8c5a0;
  border-radius: 4px;
  background-color: rgba(255, 255, 255, 0.7);
  color: #6b4b35;
  font-family: 'SimSun', 'STFangsong', serif;
  transition: all 0.3s ease;
}

.mystical-input input:focus, .mystical-select select:focus {
  outline: none;
  border-color: #bc955c;
  box-shadow: 0 0 8px rgba(188, 149, 92, 0.3);
}

.input-decoration, .select-decoration {
  position: absolute;
  right: 10px;
  pointer-events: none;
  color: #bc955c;
  font-size: 1rem;
}

.divination-button {
  text-align: center;
  margin-top: 2rem;
}

.divination-button button {
  background-color: #8b5a2b;
  color: #f9f3e9;
  border: none;
  padding: 0.8rem 2rem;
  border-radius: 4px;
  font-size: 1.1rem;
  cursor: pointer;
  font-family: 'SimSun', 'STFangsong', serif;
  position: relative;
  transition: all 0.3s ease;
  box-shadow: 0 2px 10px rgba(139, 90, 43, 0.2);
  overflow: hidden;
}

.divination-button button::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg, 
    transparent, 
    rgba(255, 255, 255, 0.2), 
    transparent
  );
  transition: 0.5s;
}

.divination-button button:hover::before {
  left: 100%;
}

.divination-button button:hover {
  background-color: #a06c33;
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(139, 90, 43, 0.3);
}

.button-text {
  position: relative;
  z-index: 1;
  letter-spacing: 2px;
}

.button-decoration {
  margin-left: 0.5rem;
  font-size: 1.2rem;
}

.scroll-footer {
  text-align: center;
  margin-top: 2rem;
}

.footer-text {
  font-size: 0.9rem;
  color: #ab7d53;
  font-style: italic;
  margin-top: 0.5rem;
}

/* 响应式调整 */
@media (max-width: 768px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
  
  .birth-form-mystical {
    padding: 1.5rem;
  }
}
</style>